//
//  DnpChooseContactDelegate.m
//  dnp_plugin
//
//

#import "DnpChooseContactDelegate.h"

@implementation DnpChooseContactDelegate

#pragma mark - CNContactPickerDelegate

- (void)contactPicker:(CNContactPickerViewController *)picker didSelectContact:(CNContact *)contact {
    
    NSMutableDictionary *data = [NSMutableDictionary dictionary];

    NSString *givenName = contact.givenName;
    NSString *familyName = contact.familyName;
    NSString *fullName = [NSString stringWithFormat:@"%@ %@", givenName, familyName];

    NSString *phone = nil;
    if (contact.phoneNumbers.count > 0) {
        phone = [contact.phoneNumbers.firstObject.value.stringValue copy];
    }

    NSDictionary *dic = @{
        @"fullName": fullName,
        @"phoneNumber": phone ? phone : [NSNull null]
    };

    if (self.result) {
        self.result(dic);
    }
}

@end
